package operation;

import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书！");
        if (bookList.getUsedSize() == 0) {
            System.out.println("书架为空，不能删除！");
            return;
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入想要删除的书名：");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if (name.equals(bookList.getBook(i).getName())) {
                for (int j = i; j < bookList.getUsedSize() - 1; j++) {
                    bookList.setBook(j, bookList.getBook(j + 1));
                }
                bookList.setUsedSize(bookList.getUsedSize() - 1);
                System.out.println("删除成功！");
                break;
            }
        }
    }
}
